<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page contentType="text/html; UTF-8" pageEncoding="UTF-8" isELIgnored="false" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>学生管理</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"/>
    <script src="${pageContext.request.contextPath}/back/statics/js/jquery-1.8.3.min.js"></script>
</head>

<script>
    // 修改表单
    function add_grade()
    {

        var credit= $.trim($('#credit2').val());
        var credithour=$.trim($("#credithour2").val());
        var textbook=$.trim($("#textbook2").val());
        var coursename=$.trim($("#coursename2").val());
        var  term=$.trim($("#term2").val());
        var  teacherid=$.trim($("#teacherid2").val());

        var courseid=$.trim($("#courseid2").val());



        $.ajax(
            {
                url: "${pageContext.request.contextPath}/course/getCourse",
                data:{courseid:courseid,teacherid:teacherid, credithour:credithour,coursename:coursename,textbook:textbook,term:term,credit:credit},
                type: "post",

                beforeSend:function()
                {
                    $("#tip2").html("<span style='color:blue'>正在处理...</span>");
                    return true;
                },
                success:function(data)
                {

                    alert("课程号为："+courseid+"的课程添加成功")
                    location.reload();
                },
                error:function()
                {
                    alert('请求出错');
                },
                complete:function()
                {
                    // $('#tips').hide();
                }
            });

        return false;
    }



    // 修改模块
    function change_course(courseid)
    {



        alert("wdwe");

        var credit= $.trim($('#credit').val());
        var credithour=$.trim($("#credithour").val());
        var textbook=$.trim($("#textbook").val());
        var coursename=$.trim($("#coursename").val());
        var  term=$.trim($("#term").val());
        var  teacherid=$.trim($("#teacherid").val());
        var status=$.trim($("#status").val());





        $.ajax(
            {
                url: "${pageContext.request.contextPath}/course/changeCourse",
                // data:{form_data:form_data,act:act},
                data:{courseid:courseid,teacherid:teacherid, credithour:credithour,coursename:coursename,textbook:textbook,term:term,credit:credit,status:status},
                type: "post",
                beforeSend:function()
                {
                    $("#tip").html("<span style='color:blue'>正在处理...</span>");
                    return true;
                },
                success:function(data)
                {
                    var msg = "修改";
                    $("#tip").html("<span style='color:blueviolet'>" +msg+ "成功！</span>");
                    alert("成绩编号为："+courseid+"的信息"+msg + "成功");
                    location.reload();
                },
                error:function()
                {
                    alert('请求出错');
                },
                complete:function()
                {
                    $('#acting_tips').hide();
                }
            });

        return false;
    }



    $(function () { $('#addUserModal').on('hide.bs.modal', function () {
        // 关闭时清空edit状态为add
        $("#act").val("add");
        location.reload();
    })
    });
</script>




<body>
<div class="container-fluid">

    <%--标题--%>
    <div class="row">
        <div class="col-sm-4 col-sm-offset-4">
            <h1 class="text-center">教师管理</h1>
        </div>
    </div>

    <%--搜索条件--%>
    <div class="row" style="margin:20px 0px;">
        <div class="col-sm-10 col-sm-offset-1 text-center">
            <form class="form-inline" action="${pageContext.request.contextPath}/teacher/findAll" method="post">
                <div class="form-group">
                    <select class="form-control" name="searchCol" id="searchCol">

                        <option value="t.sex"
                                <c:if test="${searchCol=='t.sex'}">
                                    selected
                                </c:if>
                        >性别
                        </option>
                        <option value="t.age"
                                <c:if test="${searchCol=='t.age'}">
                                    selected
                                </c:if>
                        >年龄
                        </option>
                        <option value="t.name"
                            <c:if test="${searchCol=='t.name'}">
                                selected
                            </c:if>
                    >姓名
                    </option>
                        <option value="t.depart"
                                <c:if test="${searchCol=='t.depart'}">
                                    selected
                                </c:if>
                        >部门
                        </option>

                    </select>
                </div>
                <div class="form-group">
                    <input type="text" class="form-control" name="searchValue" value="${searchValue}"
                           style="width:500px;" id="searchValue"
                           placeholder="请输入对应的搜索关键词">
                </div>
                <button type="submit" class="btn btn-primary">查询</button>
            </form>
        </div>
    </div>
    <%--添加按钮--%>
    <div class="row" style="margin-bottom: 14px;">
        <div class="col-sm-12">
            <a href="${pageContext.request.contextPath}/back/student/add.jsp" class="btn btn-success">添加</a>
        </div>
    </div>

    <%--表格--%>
    <div class="row" style="height: 600px;">
        <div class="col-sm-12">
            <c:if test="${teachers.size()==0}">
                <h1 class="text-center text-info">还没有任何数据~~~</h1>
            </c:if>

            <c:if test="${teachers.size()>0}">
                <table class="table table-striped table-hover table-bordered">
                    <tr>
                        <th>工号</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>年龄</th>
                        <th>电话</th>
                        <th>部门</th>
                        <th>操作</th>
                    </tr>
                        <%--循环域中的学生集合。展示数据--%>
                    <c:forEach items="${teachers}" var="teacher">
                        <tr>
                            <td>${teacher.teaid}</td>
                            <td>${teacher.name}</td>
                            <td>${teacher.sex}</td>
                            <td>${teacher.age}</td>
                            <td>${teacher.phone}</td>
                            <td>${teacher.depart}</td>
                            <td>
                                <button type="button" class="btn btn-info" data-toggle="modal"  data-target="#addUserModal">修改</button>
                                <a href="${pageContext.request.contextPath}/course/deleteCourse?courseid=${course.courseid}" class="btn btn-danger">删除</a>

                                <!-- 模态框 -->
                                <form method="post" action="" class="form-horizontal" role="form" id="form_data" onsubmit="return change_course(${course.courseid})" style="margin: 20px;">
                                    <div class="modal fade" id="addUserModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                                        &times;
                                                    </button>
                                                    <h4 class="modal-title" id="myModalLabel">
                                                        课程号为${course.courseid}的信息
                                                    </h4>
                                                </div>
                                                <div class="modal-body">
                                                    <form class="form-horizontal" role="form" title="${course.courseid}">


                                                        <div class="form-group">
                                                            <label for="coursename" class="col-sm-3 control-label">课程名</label>
                                                            <div class="col-sm-9">
                                                                <input type="text" class="form-control" name="coursename" value="${course.coursename}" id="coursename"
                                                                       placeholder="请输入课程名" >
                                                            </div>
                                                        </div>



                                                        <div class="form-group">
                                                            <label for="credit" class="col-sm-3 control-label">学分</label>
                                                            <div class="col-sm-9">
                                                                <input type="text" class="form-control" name="credit"  id="credit"
                                                                       placeholder="请输入学分" >
                                                            </div>
                                                        </div>

                                                        <div class="form-group">
                                                            <label for="credithour" class="col-sm-3 control-label">学时</label>
                                                            <div class="col-sm-9">
                                                                <input type="text" class="form-control" name="credithour"  value="${course.credithour}" id="credithour"
                                                                       placeholder="请输入学时" >
                                                            </div>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="textbook" class="col-sm-3 control-label">课本名</label>
                                                            <div class="col-sm-9">
                                                                <input type="text" class="form-control" name="textbook" value="${course.textbook}" id="textbook"
                                                                       placeholder="请输入课本">${course.textbook}
                                                            </div>
                                                        </div>

                                                        <div class="form-group">
                                                            <label for="term" class="col-sm-3 control-label">学期</label>
                                                            <div class="col-sm-9">
                                                                <input type="text" class="form-control" name="term" value="${course.term}" id="term"
                                                                       placeholder="请输入学期">
                                                            </div>
                                                        </div>

                                                        <div class="form-group">
                                                            <label for="teacherid" class="col-sm-3 control-label">教师工号</label>
                                                            <div class="col-sm-9">
                                                                <input type="text" class="form-control" name="teacherid" value="${course.teacherid}" id="teacherid"
                                                                       placeholder="请输入教师工号">
                                                            </div>
                                                        </div>


                                                        <div class="form-group">
                                                            <label for="status" class="col-sm-3 control-label">课程状态:${course.status}</label>
                                                            <div class="col-sm-9">
                                                                <select name="status" id="status"  class="form-control" >
                                                                    <option value="已选">已选</option>
                                                                    <option value="未选">未选</option>
                                                                </select>
                                                            </div>
                                                        </div>




                                                    </form>
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                                    </button>
                                                    <button type="submit" class="btn btn-primary">
                                                        提交
                                                    </button><span id="tip"> </span>
                                                </div>
                                            </div><!-- /.modal-content -->
                                        </div><!-- /.modal -->
                                    </div>
                                </form>
                            </td>
                        </tr>
                    </c:forEach>
                </table>
            </c:if>
        </div>
    </div>




        <!-- 模态框（Modal2） -->
        <form method="post" action="" class="form-horizontal" role="form" id="form_data2" onsubmit="return  add_grade()" style="margin: 20px;">
            <div class="modal fade" id="addUserModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                &times;
                            </button>
                            <h4 class="modal-title" id="mModalLabel">
                                添加课程信息
                            </h4>
                        </div>
                        <div class="modal-body">
                            <form class="form-horizontal" role="form" title="${course.courseid}">
                                <div class="form-group">
                                    <label for="courseid2" class="col-sm-3 control-label">课程号</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" id="courseid2" name="courseid"
                                               placeholder="请输入课程号">
                                    </div>
                                </div>


                                <div class="form-group">
                                    <label for="coursename" class="col-sm-3 control-label">课程名</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" name="coursename"  id="coursename2"
                                               placeholder="请输入课程名" >
                                    </div>
                                </div>



                                <div class="form-group">
                                    <label for="credit" class="col-sm-3 control-label">学分</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" name="credit"  id="credit2"
                                               placeholder="请输入学分" >
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="credithour" class="col-sm-3 control-label">学时</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" name="credithour"   id="credithour2"
                                               placeholder="请输入学时" >
                                    </div>
                                </div>


                                <div class="form-group">
                                    <label for="term" class="col-sm-3 control-label">学期</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" name="term"  id="term2"
                                               placeholder="请输入学期">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="textbook" class="col-sm-3 control-label">课本名</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" name="textbook"  id="textbook2"
                                               placeholder="请输入课本">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label for="teacherid" class="col-sm-3 control-label">教师工号</label>
                                    <div class="col-sm-9">
                                        <input type="text" class="form-control" name="teacherid"  id="teacherid2"
                                               placeholder="请输入教师工号">
                                    </div>
                                </div>






                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                            </button>
                            <button type="submit" class="btn btn-primary">
                                提交
                            </button><span id="tip2"> </span>
                        </div>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal -->
            </div>
        </form>



    <%--分页工具栏--%>
    <div class="row" style="margin-top: -300px">
        <div class="col-sm-12 text-center">
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    <li>
                        <c:if test="${page>1}">
                            <a href="${pageContext.request.contextPath}/teacher/findAll?page=${page-1}&searchCol=${searchCol}&searchValue=${searchValue}" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </c:if>
                    </li>
                    <c:forEach begin="1" step="1" end="${pages}" varStatus="state">
                        <li><a href="${pageContext.request.contextPath}/teacher/findAll?page=${state.count}&searchCol=${searchCol}&searchValue=${searchValue}">${state.count}</a></li>
                    </c:forEach>

                    <li>
                        <c:if test="${page<pages}">
                            <a href="${pageContext.request.contextPath}/teacher/findAll?page=${page+1}&searchCol=${searchCol}&searchValue=${searchValue}" aria-label="Previous">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </c:if>

                    </li>
                </ul>
            </nav>
        </div>
    </div>

</div>


</body>